<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-inner">
      <div class="logo">
        <img class="img" src='@/assets/images/book-logo.png' alt="">
      </div>
      <div class="login-con">
        <Card icon="log-in" :bordered="false">
          <div class="form-con">
            <p class="login-title">
              {{$t('welcome_login')}}
            </p>
            <login-form @on-success-valid="handleSubmit"></login-form>
            <a :href="hrefUrl" target="_blank">{{$t('Browser')}}</a>
          </div>
        </Card>
      </div>
      <div class="login-copyright">
        © 2020 XXXX平台 Version:{{version}} - Powered By <a href="https://blog.csdn.net/xionglangs" target="_blank">XXXXX有限公司</a>
      </div>

    </div>
  </div>
</template>

<script>
  import config from '@/config'
  import LoginForm from '_c/login-form'
  import {mapActions,mapMutations} from 'vuex'

  export default {
    components: {
      LoginForm,
    },
    data() {
      return {
        version: config.version,
        hrefUrl: '',
        downloadFileName: '',
      }
    },
    activated() {
      this.initLinkFile()
    },
    mounted() {
      this.initLinkFile()
    },
    methods: {
      ...
        mapActions([
          'handleLogin',
          'getUserDetailByToken',
        ]),
      ...mapMutations([
        'setLocal',
      ]),
      handleSubmit({username, password}) {
        this.handleLogin({username, password}).then(res => {
          if (!res.result) {
            this.$Message.warning({content: res.errorMsg})
          } else {
            this.getUserDetailByToken().then(res => {
              if (res.result) {
                this.$router.push({
                  name: this.$config.homeName
                })
              }else{
                this.$Message.error({content: res.errorMsg})
              }
            })
          }
        }).catch(err => {
          console.log(err)
        })
      },
      initLinkFile() {
        let agent = navigator.userAgent.toLowerCase();
        if (agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0) {
          //this.hrefUrl = "https://dlc2.pconline.com.cn/filedown_51614_13767262/8agq1y5i/ChromeSetup_64.exe"
          // this.downloadFileName = "ChromeSetup_64.exe"
        } else {
          //this.hrefUrl = "https://dlc2.pconline.com.cn/filedown_51614_13767267/8agq1y5i/ChromeSetup_32.exe"
          // this.downloadFileName = "ChromeSetup_32.exe"
        }
        this.hrefUrl="https://www.google.cn/chrome/"
      }
    }
  }
</script>
